package algorithm.recursive;

import org.junit.validator.PublicClassValidator;

import java.util.ArrayList;
import java.util.List;

/**
 * @author keyer
 * @Description : 描述
 * Created by cyd on 2021-06-15 10:13:23
 */
public class FibonacciList {
    private final ArrayList<Integer> list = new ArrayList<>();

    public List<Integer> fillList(Integer n) {
        if (n == 0) {
            list.add(0);
            return list;
        } else if (n == 1) {
            list.add(0);
            list.add(1);
            return list;
        }
        if (n >= 2) {
            list.add(0);
            list.add(1);
            for (int i = 2; i <= n; i++) {
                list.add(list.get(i - 1) + list.get(i - 2));
            }
        }
        return list;
    }

    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        FibonacciList fibonacciList = new FibonacciList();
        List<Integer> list = fibonacciList.fillList(50);
        System.out.println(list);
        long end = System.currentTimeMillis();
        System.out.println(end-start);
    }
}
